/**
 * 
 * The brick manager manages everything related to bricks for the game.
 * 
 * Author: Matthias Van Eeghem <matthias@van-eeghem.com>
 * All rights reserved.
 * 
 */

package com.bomberman.brick;

import java.util.ArrayList;
import java.util.Iterator;

import com.bomberman.core.Element;

public class BrickManager 
{
	/**
	 * Holds the list of all bricks already created.
	 */
	private static ArrayList<Brick> brickList = new ArrayList<Brick>();

	/**
	 * Adds a brick to the field
	 * 
	 * @param brick The brick object to add
	 */
	
	public static void addBrick(Brick brick)
	{
		// Push back the object on the brick list
		brickList.add(brick);
	}
	
	/**
	 * Returns the brick list.
	 * 
	 * @return The brick list
	 */
	
	public static ArrayList<Brick> getBrickList()
	{
		return brickList;
	}
	
	/**
	 * Removes a brick at a certain column and row.
	 * 
	 * @param row The brick's row
	 * @param column The brick's column
	 */
	public static void removeBrickAt(int row, int column)
	{
		// Brick iterator
		Iterator<Brick> iterator = getBrickList().iterator();
		
		while(iterator.hasNext())
		{
			// Save the brick object
			Brick brick = iterator.next();
			
			// We have a brick match
			if(brick.getRow() == row && brick.getColumn() == column)
			{
				// Remove the iterator from the brick list
				iterator.remove();
				Element.remove(brick);
				break;
			}
		}
	}
}
